var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, n, a) {
    var o, i = arguments.length, s = i < 3 ? t : null === a ? a = Object.getOwnPropertyDescriptor(t, n) : a;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, n, a); else for (var r = e.length - 1; 0 <= r; r--) (o = e[r]) && (s = (i < 3 ? o(s) : 3 < i ? o(t, n, s) : o(t, n)) || s);
    return 3 < i && s && Object.defineProperty(t, n, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("PersonView"), s = e("BattleHeadView"), c = e("BattleRewardView"), l = e("PrefabView"), d = e("Global"), u = e("GameManager"), p = e("PetManager"), h = e("AudioManager"), f = e("MyButton"), g = e("GameConfig"), m = e("GameData"), y = e("EggsManager"), v = e("ActivityManager"), w = e("DataManager"), b = e("WebManager"), P = e("UIManager"), I = e("AdManager"), G = e("DrawManager"), _ = e("FSVideoAdManager"), A = cc._decorator, k = A.ccclass, M = A.property, C = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.myButton = null, e.nextBtn = null, e.personView = null, e.headItem = null, 
        e.rewardItem = null, e.mvp = null, e.win = null, e.lose = null, e.nameLabel = null, 
        e.aimLabel = null, e.scoreLabel = null, e.scoreRichText = null, e.count = 0, e.score = 0, 
        e.diamond = 0, e.money = 0, e.piece = 0, e.reward = [], e.isEffect = !1, e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        var e, t;
        v.ActivityManager.getInstance().checkActivity(v.ActivityType.NEWYEAR) ? 5 == m.GD.personIdx ? m.GD.newYearSkinCount < g.GC.newYearSkinCount && (m.GD.newYearSkinCount++, 
        m.GD.newYearSkinCount == g.GC.newYearSkinCount && (m.GD.newYearDrawTotal = 3)) : m.GD.newYearSkinCount < g.GC.newYearSkinCount && (m.GD.newYearSkinCount = 0) : v.ActivityManager.getInstance().checkActivity(v.ActivityType.CHRISTMAS) && (4 == m.GD.personIdx ? m.GD.christmasSkinCount < g.GC.christmasSkinCount && (m.GD.christmasSkinCount++, 
        m.GD.christmasSkinCount == g.GC.christmasSkinCount && (m.GD.christmasDrawTotal = 3)) : m.GD.christmasSkinCount < g.GC.christmasSkinCount && (m.GD.christmasSkinCount = 0)), 
        d.G.playcount++, (GA.isOPPO() || GA.isPlatform(GA.Platform.Vivo) || d.G.isNative()) && g.GC.nativeAdConfig.a && (g.GC.nativeAdConfig.d < 1 && (g.GC.nativeAdConfig.d = 1), 
        g.GC.nativeAdConfig.n <= d.G.playcount && (d.G.playcount - g.GC.nativeAdConfig.n) % g.GC.nativeAdConfig.d == 0 && (I.default.getInstance().nativeFlag = 1)), 
        m.GD.gunIdx < 2e3 && (m.GD.gunIdx < 0 || 1e3 <= m.GD.gunIdx) && (e = d.G.getEggIdx(m.GD.gunIdx), 
        (t = y.default.getInstance().getDataGun(e)) && t.time + 1e3 * g.GC.eggTime - Date.now() <= 0 && (0 < y.default.getInstance().checkEggGun(e) ? y.default.getInstance().updateEggGun(e) : m.GD.gunIdx = m.GD.topRank)), 
        m.GD.personIdx < 0 && (28 != (e = d.G.getEggIdx(m.GD.personIdx, 2)) || !(t = y.default.getInstance().getDataPerson(e)).time || t.time < Date.now()) && (0 < y.default.getInstance().checkEggPerson(e) ? y.default.getInstance().updateEggPerson(e) : m.GD.personIdx = m.GD.skins[m.GD.skins.length - 1]), 
        !p.default.getInstance().isHas(1) && 0 < m.GD.hatchLastTime && Math.floor((Date.now() - m.GD.hatchLastTime) / 1e3) >= g.GC.hatchConfig.time && cc.systemEvent.emit("hatch_reward");
    }, e.prototype.onDisable = function() {
        u.default.getInstance().quitGame(), cc.systemEvent.off("star", this.callback, this), 
        _.default.getInstance().doShowFSVideo(this.text), t.prototype.onDisable.call(this);
    }, e.prototype.onDestroy = function() {
        t.prototype.onDestroy.call(this), P.default.getInstance().showPnl("start");
    }, e.prototype.onClickVideo = function() {
        var t = this;
        if (g.GC.isDebug && GA.Info.underCheck) return cc.systemEvent.emit("videoEnd", "star"), 
        void this.callback();
        b.default.getInstance().sentLog("点击结算界面视频加积分按键"), GA.rewardOperation({
            tag: "star",
            page: "",
            byVideo: !0,
            result: function(e) {
                e.reward && (cc.systemEvent.emit("videoEnd", "star"), cc.isValid(t) && t.callback());
            }
        });
    }, e.prototype.onClickShare = function() {
        var t = this;
        g.GC.isDebug && GA.Info.underCheck ? this.callback() : (b.default.getInstance().sentLog("点击结算界面分享加积分按键"), 
        GA.rewardOperation({
            tag: "star",
            page: "",
            byVideo: !1,
            result: function(e) {
                e.reward && cc.isValid(t) && t.callback();
            }
        }));
    }, e.prototype.onClickNext = function() {
        h.default.getInstance().playAudio("按钮2"), this.isEffect || (b.default.getInstance().sentLog("点击结算界面继续按键"), 
        "GameAssistantWeb" in window && window.GameAssistantWeb.showFullScreenVideoAd(), 
        u.default.getInstance().matchType == u.MatchType.引导 ? (m.GD.finishGide(0), b.default.getInstance().sentLog("引导战斗完成")) : 0 < this.piece ? P.default.getInstance().showToast({
            money: this.money,
            diamond: this.diamond,
            piece: this.piece
        }) : P.default.getInstance().showToast({
            money: this.money,
            diamond: this.diamond
        }), this.hidePnl());
    }, e.prototype.onClickBack = function() {
        h.default.getInstance().playAudio("按钮2"), b.default.getInstance().sentLog("点击结算界面返回按键"), 
        this.hidePnl();
    }, e.prototype.start = function() {
        var e = this, t = this.mvp.getComponent(sp.Skeleton);
        t.premultipliedAlpha=false
        t && (t.setAnimation(0, "chuxian", !1), t.premultipliedAlpha = false, t.setCompleteListener(function() {
            t.setCompleteListener(null), t.setAnimation(0, "idle", !0);
        })), this.scheduleOnce(function() {
            e.nextBtn.node.active = !0;
        }, g.GC.accountDelayTime), cc.systemEvent.on("star", this.callback, this), GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) && P.default.getInstance().loadPnl("recorderShow");
    }, e.prototype.getScoreConfig = function(e) {
        void 0 === e && (e = m.GD.curScore);
        for (var t = 0; t < g.GC.peakScoreConfig.length - 1 && e >= g.GC.peakScoreConfig[t].score; ) t++;
        return g.GC.peakScoreConfig[t];
    }, e.prototype.callback = function() {
        this.myButton.getComponent(cc.Button).interactable = !1, this.score = Math.abs(this.score), 
        m.GD.score += this.score, GA.Info.underCheck || g.GC.isDebug || b.default.getInstance().saveMatchRank({
            score: m.GD.score,
            needHeadIcon: 0
        }), w.default.getInstance().save(), this.updateScore();
    }, e.prototype.init = function() {
        this.count = m.GD.score, this.scoreLabel.string = m.GD.score.toString();
        var e = u.default.getInstance().model.players.filter(function(e) {
            return e.group == u.default.getInstance().model.curPlayer.group;
        }).sort(function(e, t) {
            return t.kill_count - e.kill_count;
        });
        if (0 < e.length) {
            for (var t = 1; this.headItem.node.parent.childrenCount < e.length; ) {
                var n = cc.instantiate(this.headItem.node);
                n.parent = this.headItem.node.parent, n.getComponent(s.default).init(e[t]), t++;
            }
            e[0].is_mvp = 1, this.headItem.init(e[0]);
            var a = cc.instantiate(this.mvp);
            a.parent = this.headItem.node, a.scale = .3, a.setPosition(cc.v2(-57, 38)), a.getComponent(sp.Skeleton).premultipliedAlpha = false, a.getComponent(sp.Skeleton).setAnimation(0, "idle", !0), 
            e[0].openid == GA.Info.openId ? this.personView.init() : this.personView.init(e[0].personIdx), 
            this.nameLabel.string = e[0].nickname ? 5 < e[0].nickname.length ? e[0].nickname.substr(0, 5) + "..." : e[0].nickname : "匿名";
        }
        a = u.default.getInstance().model.curPlayer;
        this.updateValue(a), this.score < 0 ? this.scoreRichText.string = m.GD.score + "（" + this.score + "）" : this.scoreRichText.string = m.GD.score + "（+" + this.score + "）", 
        this.updateScore(), a.is_win ? (this.win.active = !0, this.lose.active = !1, this.myButton.init("star", "积分翻倍")) : (this.win.active = !1, 
        this.lose.active = !0, this.myButton.init("star", "不扣积分"));
    }, e.prototype.updateValue = function(e) {
        switch (m.GD.killNum += e.kill_count, e.rank) {
          case 0:
            e.is_win ? (h.default.getInstance().playAudio("游戏成功"), this.diamond = 10, this.piece = GA.rand(1, 5)) : (h.default.getInstance().playAudio("游戏失败"), 
            this.diamond = 6);
            break;

          case 1:
            h.default.getInstance().playAudio("游戏失败"), this.diamond = 5;
            break;

          case 2:
            h.default.getInstance().playAudio("游戏失败"), this.diamond = 4;
            break;

          default:
            h.default.getInstance().playAudio("游戏失败"), this.diamond = 3;
        }
        var t = this.getScoreConfig();
        this.aimLabel.string = t.score.toString(), this.showReward(this.getReward(t.score));
        var n = Math.max(g.GC.reward_max - g.GC.reward_reduce * Math.floor(m.GD.topRank / g.GC.reward_interval), g.GC.reward_min);
        e.is_win ? (d.G.winlast ? (d.G.wincount++, b.default.getInstance().sentLog("连胜", d.G.wincount)) : (d.G.winlast = 1, 
        d.G.wincount = 1, d.G.losecount = 0), m.GD.updateNumber("winNum", 1), this.money = Math.floor(d.G.getPrice(m.GD.topRank) * n) + 200, 
        e.is_mvp ? this.score = Math.round((isNaN(t.base) ? g.GC.peakBase : t.base) * t.win * (1 + (isNaN(t.mvp) ? g.GC.peakMvp : t.mvp))) : this.score = Math.round((isNaN(t.base) ? g.GC.peakBase : t.base) * t.win)) : (d.G.winlast ? (d.G.winlast = 0, 
        d.G.wincount = 0, d.G.losecount = 1) : (d.G.losecount++, m.GD.tryFailCount = 0, 
        b.default.getInstance().sentLog("连败", d.G.losecount)), this.money = Math.floor(d.G.getPrice(m.GD.topRank) * n / 10) + 20, 
        e.is_mvp ? this.score = -Math.round((isNaN(t.base) ? g.GC.peakBase : t.base) * t.lose * (1 + (isNaN(t.mvp) ? g.GC.peakMvp : t.mvp))) : this.score = -Math.round((isNaN(t.base) ? g.GC.peakBase : t.base) * t.lose)), 
        p.default.getInstance().check(), m.GD.updateNumber("diamond", this.diamond), m.GD.updateNumber("money", this.money), 
        m.GD.updateNumber("piece", this.piece), m.GD.score = Math.max(m.GD.score + this.score, 0), 
        m.GD.score > m.GD.topScore && (m.GD.topScore = m.GD.score), GA.Info.underCheck || g.GC.isDebug || b.default.getInstance().saveMatchRank({
            score: m.GD.score,
            needHeadIcon: 0
        }), w.default.getInstance().upload({
            json: !0,
            local: !0,
            killNum: m.GD.killNum
        });
    }, e.prototype.updateScore = function() {
        this.isEffect = !0, 0 < this.score ? this.scoreLabel.node.color = cc.Color.GREEN : this.score < 0 && (this.scoreLabel.node.color = cc.Color.RED);
    }, e.prototype.doReward = function(e) {
        this.reward = this.getReward(e);
        var a = null;
        0 < this.reward.length && (this.reward.forEach(function(e) {
            switch (e.type) {
              case d.RewardType.DIAMOND:
                m.GD.updateNumber("diamond", e.num);
                break;

              case d.RewardType.SKIN:
                m.GD.addSkin(e.idx) && w.default.getInstance().upload({
                    json: !0,
                    local: !0,
                    skin: e.idx
                }), m.GD.personIdx < e.idx && (m.GD.personIdx = e.idx);
                break;

              case d.RewardType.PET:
                p.default.getInstance().isHas(0) || (p.default.getInstance().getRealData(0).has = 1, 
                m.GD.petDataIdx = 0);
                break;

              case d.RewardType.ARM:
                var t = P.default.getInstance().getPnl("start"), n = t.boxs.filter(function(e) {
                    return e.isEmpty();
                });
                0 < n.length ? (t.appendItem(e.idx, n[0]), t.updateMatrix()) : t.appendEquip(e.idx), 
                2001 == e.idx && 3 != m.GD.personIdx && 9 != m.GD.personIdx || (m.GD.gunIdx = e.idx), 
                1008 == e.idx && -17 != m.GD.personIdx || (m.GD.gunIdx = e.idx);
                break;

              case d.RewardType.PIECE:
                m.GD.updateNumber("piece", e.num);
                break;

              case d.RewardType.ELF:
                p.default.getInstance().isHas(2) || (p.default.getInstance().getRealData(2).has = 1, 
                m.GD.petDataIdx = 2);
                break;

              case d.RewardType.BOX:
                a = G.default.getInstance().doDraw();
            }
        }), m.GD.curScore < e && (m.GD.curScore = e), w.default.getInstance().save(), this.reward[this.reward.length - 1].type == d.RewardType.BOX && a ? P.default.getInstance().loadPopPnl("draw_reward", a) : P.default.getInstance().loadPopPnl("reward", this.reward[this.reward.length - 1]));
    }, e.prototype.getReward = function(e) {
        for (var t = [], n = 0; n < g.GC.peakRewardList.length; n++) {
            var a = g.GC.peakRewardList[n];
            e >= a.score && m.GD.curScore < a.score && t.push(a);
        }
        return t;
    }, e.prototype.showReward = function(e) {
        0 < e.length && this.rewardItem.init(e[e.length - 1]);
    }, e.prototype.update = function() {
        var e;
        this.isEffect && (this.count < m.GD.score ? (this.count++, this.scoreLabel.string = this.count.toString()) : this.count > m.GD.score ? (this.count--, 
        this.scoreLabel.string = this.count.toString()) : (this.scoreLabel.node.color = cc.Color.WHITE, 
        this.isEffect = !1, this.doReward(m.GD.score), e = this.getScoreConfig(), this.aimLabel.string = e.score.toString(), 
        this.showReward(this.getReward(e.score))));
    }, a([ M(f.default) ], e.prototype, "myButton", void 0), a([ M(cc.Button) ], e.prototype, "nextBtn", void 0), 
    a([ M(r.default) ], e.prototype, "personView", void 0), a([ M(s.default) ], e.prototype, "headItem", void 0), 
    a([ M(c.default) ], e.prototype, "rewardItem", void 0), a([ M(cc.Node) ], e.prototype, "mvp", void 0), 
    a([ M(cc.Node) ], e.prototype, "win", void 0), a([ M(cc.Node) ], e.prototype, "lose", void 0), 
    a([ M(cc.Label) ], e.prototype, "nameLabel", void 0), a([ M(cc.Label) ], e.prototype, "aimLabel", void 0), 
    a([ M(cc.Label) ], e.prototype, "scoreLabel", void 0), a([ M(cc.Label) ], e.prototype, "scoreRichText", void 0), 
    a([ k ], e);
}(l.default);

n.default = C;